function Stack() {
    this.count = 0
    this.items = {}
}

Stack.prototype.push = function (element) {
    this.items[this.count] = element
    this.count++
}
Stack.prototype.size = function () {
    return this.count
}

Stack.prototype.isEmpty = function () {
    return this.size() === 0
}

Stack.prototype.pop = function () {
    if (this.isEmpty()) {
        return undefined
    }
    this.count--
    const result = this.items[this.count]
    delete this.items[this.count]
    return result
}


Stack.prototype.peek = function () {
    return this.items[this.count - 1]
}

Stack.prototype.clear = function () {
    this.count = 0
    this.items = {}
}
// Stack.prototype.toString = function () {
//     if (this.isEmpty()) {
//         return ''
//     }
//     let str = this.items['0']
//     for (let i = 1; i < this.count; i++) {
//         str = `${str},${this.items[i]}`
//     }
//     return str
// }


export default Stack


